package com.yun.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsPageDTO;
import com.heima.model.wemedia.dtos.WmTakenDownDTO;
import com.yun.wemedia.service.WmNewsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: yu
 * @data 2025年07月30日 17:29
 */
@RestController
@RequestMapping("/api/v1/news")
@RequiredArgsConstructor
public class WmNewsController {

    private final WmNewsService wmNewsService;


    /**
     * @description: 获取文章
     * @title: findList
     * @param: [wmNewsPageDTO]
     */
    @PostMapping("/list")
    ResponseResult findList(@RequestBody WmNewsPageDTO wmNewsPageDTO) {
        return wmNewsService.queryList(wmNewsPageDTO);
    }


    /**
     * @description: 提交或修改文章
     * @title: submitOrUpdate
     * @param: [wmNewsDTO]
     */
    @PostMapping("/submit")
    ResponseResult submitOrUpdate(@RequestBody WmNewsDTO wmNewsDTO) {
        wmNewsService.submitOrUpdate(wmNewsDTO);
        return ResponseResult.okResult("操作成功");
    }


    /**
     * @description: 下架文章
     * @title: takenDown
     * @param: []
     */
    @PostMapping("down_or_up")
    ResponseResult takenDown(@RequestBody WmTakenDownDTO wmTakenDownDTO) {
        return wmNewsService.isDown(wmTakenDownDTO);
    }

    /**
     * @description: 获取一个wmNews队形
     * @title: getOneWmNews
     * @param: []
     */
    @GetMapping("/one/{id}")
    ResponseResult getOneWmNews(@PathVariable Integer id) {
        return ResponseResult.okResult(wmNewsService.getById(id));
    }

}
